data <- read.csv(file = "..\Data\train.csv", header = TRUE, stringsAsFactors = FALSE)
attach(data)
names(data)

numberofclasses <- 3
fareceiling <- 40
fare[fare>fareceiling] <- fareceiling-1
farebracketsize <- 10
numberofpricebrackets <- fareceiling / farebracketsize

survivaltable <- array(0, dim=c(2, numberofclasses, numberofpricebrackets))

for (i in 1:numberofclasses){
for (j in 1:numberofpricebrackets){
womenonlyclassstats <- survived[(sex == "female") & (pclass == i) & 
(fare >= (j-1)fare_bracket_size) & (fare < jfarebracketsize)]

    men_only_class_stats <- survived[(sex == "male") & (pclass == i) & 
    (fare >= (j-1)*fare_bracket_size) & (fare < j*fare_bracket_size)]

    survival_table[1,i,j] <- mean(women_only_class_stats)
    survival_table[2,i,j] <- mean(men_only_class_stats)     
}
}

survivaltable[is.nan(survivaltable)] <- 0

survivaltable[ survivaltable < 0.5 ] <- 0
survivaltable[ survivaltable >= 0.5 ] <- 1



